<template>
  <div class="resume-analysis">
    <div class="page-header">
      <h1 class="page-title">面试测评</h1>
      <div class="header-buttons">
        <button class="back-btn" @click="$router.push('/mock-interview')">返回</button>
      </div>
    </div>

    <div class="analysis-content">
      <div class="result-panel" v-if="evaluation">
        <div class="panel-title">综合评价</div>
        <div class="score-display">
          <div class="score-circle">
            <div class="score">{{ evaluation.overallScore }}</div>
            <div class="score-label">档位</div>
          </div>
          <div class="score-details">
            <div class="section">
              <div class="sub-title">优势亮点</div>
              <div class="content-text">{{ formatAsText(evaluation.strengths) }}</div>
            </div>
            <div class="section">
              <div class="sub-title">关键不足</div>
              <div class="content-text">{{ formatAsText(evaluation.weaknesses) }}</div>
            </div>
            <div class="section">
              <div class="sub-title">改进建议</div>
              <div class="content-text">{{ formatAsText(evaluation.suggestions) }}</div>
            </div>
          </div>
        </div>
      </div>

      <div class="result-panel" v-if="evaluation && evaluation.dimensions">
        <div class="panel-title">维度评分</div>
        <div class="advantages">
          <div class="advantage-item" v-for="(v, k) in evaluation.dimensions" :key="k">
            <span class="advantage-icon"></span>
            <div><strong>{{ k }}：</strong>{{ v }}</div>
          </div>
        </div>
      </div>

      <div class="result-panel" v-if="evaluation && evaluation.positionMatch">
        <div class="panel-title">岗位匹配度</div>
        <div class="suggestions">
          <div class="suggestion-item">{{ evaluation.positionMatch }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { checkAndEvaluateInterview } from '@/api/aiChatApi'
export default {
  name: 'InterviewEvaluation',
  data() {
    return {
      evaluation: null
    }
  },
  async mounted() {
    const sessionId = this.$route.query.sessionId || this.$route.params.sessionId
    if (!sessionId) return
    try {
      const r = await checkAndEvaluateInterview(sessionId)
      if (r && (r.code === 200 || r.code === 0)) {
        this.evaluation = r.data && r.data.evaluation
      }
    } catch (e) {
      console.error('获取面试测评失败', e)
    }
  },
  methods: {
    formatAsText(items) {
      if (!items || !Array.isArray(items)) {
        return '暂无相关内容'
      }
      return items.join('；')
    }
  }
}
</script>

<style scoped>
.resume-analysis {
  min-height: 100vh;
  height: 100vh;
  background: #010e50 url(@/assets/images/bg.jpg) center top no-repeat;
  background-size: 100% auto;
  color: #fff;
  padding: 2rem;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  flex-shrink: 0;
}

.page-title {
  font-size: 2.5rem;
  font-weight: bold;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.header-buttons { display: flex; gap: 10px; }
.back-btn {
  padding: 0.8rem 1.5rem;
  background: linear-gradient(135deg, rgba(2, 88, 240, 0.3), rgba(0, 35, 120, 0.5));
  border: 1px solid rgba(100, 162, 255, 0.4);
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  transition: all 0.3s ease;
}
.back-btn:hover {
  background: linear-gradient(135deg, rgba(2, 88, 240, 0.5), rgba(0, 35, 120, 0.7));
  border-color: #0258f0;
}

.analysis-content { display: grid; gap: 2rem; flex: 1; overflow-y: auto; padding-bottom: 2rem; }
.result-panel {
  background: rgba(0, 35, 120, 0.36);
  border: 1px solid rgba(100, 162, 255, 0.2);
  border-radius: 8px;
  padding: 1.5rem;
  position: relative;
  margin-bottom: 1.5rem;
}
.panel-title {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid rgba(2, 88, 240, 0.4);
}

.score-display { display: flex; align-items: center; gap: 2rem; }
.score-circle {
  width: 120px; height: 120px;
  border: 3px solid #0258f0; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(2, 88, 240, 0.1);
}
.score { font-size: 2.5rem; font-weight: bold; color: #0258f0; }
.score-label { font-size: 1rem; color: #64a2ff; }
.score-details { flex: 1; }

.section {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: rgba(2, 88, 240, 0.08);
  border: 1px solid rgba(100, 162, 255, 0.15);
  border-radius: 8px;
  position: relative;
}

.section:last-child {
  margin-bottom: 0;
}

.section::before {
  content: '';
  position: absolute;
  top: -1px;
  left: -1px;
  width: 15px;
  height: 20px;
  border-left: 1px solid #0258f0;
  border-top: 1px solid #0258f0;
}

.section::after {
  content: '';
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 15px;
  height: 20px;
  border-right: 1px solid #0258f0;
  border-bottom: 1px solid #0258f0;
}

.sub-title {
  font-size: 1rem;
  font-weight: 600;
  color: #64a2ff;
  margin: 0 0 12px 0;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(100, 162, 255, 0.2);
}

.content-text {
  color: rgba(255, 255, 255, 0.9);
  line-height: 1.6;
  font-size: 0.95rem;
  text-align: justify;
}

.advantages, .suggestions { display: grid; gap: 0.8rem; }
.advantage-item, .suggestion-item {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.8rem; background: rgba(2, 88, 240, 0.1); border-radius: 6px;
  border-left: 3px solid rgba(100, 162, 255, 0.3);
}
.advantage-icon { color: #4CAF50; font-weight: bold; }
</style>


